<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/6/1
 * Time: 11:41
 */

namespace app\model\index;

use think\model\concern\SoftDelete;

class User extends Base
{
    use SoftDelete;
    protected $autoWriteTimestamp = 'datetime';
    protected $append = [
        'status_text',
        'is_son_text',
        'rule_text',
        'login_date'
    ];

    public function getLoginDateAttr($value,$data){
        $time = empty($data['login_time']) ? $data['create_time'] : $data['login_time'];
        return date('Y-m-d',strtotime($time));
    }

    public function getRuleTextAttr($value,$data){
        $text = [
            'users' => '用户管理权限',
            'web' => '网站管理权限',
            'history' => '关键词历史查询',
            'order' => '订单',
            'message' => '关键词数据',
            'setmenu' => '套餐设定',
            'project' => '项目权限',
            'BaiduKeywordsSpotting' => '百度关键词监听',
            'DouyinKeywordsSpotting' => '抖音关键词监听'
        ];
        $array = json_decode($data['rule'],true);
        if (empty($array))return '无';
        foreach ($array AS $key => $value){
            $arr[] = $text[$value];
        }
        return implode(',',$arr);
    }

    public function getIsSonTextAttr($value,$data){
        $array = [
            '0' => '禁用',
            '1' => '正常',
            '2' => '禁用'
        ];
        return $array[$data['is_son']] ?? '禁用';
    }

    public function getStatusTextAttr($value,$data){
        $array = [
            1 => '正常',
            2 => '禁用',
            3 => '待激活'
        ];
        return $array[$data['status']];
    }
}